classic_battlefield_moddingfandomcom-20200214-history
AIBehaviors and the Navmesh
Thanks to LT Fred for figuring a lot of this out and explaining it to me. This article explains the relationship between the AiBehaviors and the Navmesh in BF2 and BF2142. The AIBehaviors lists all the possible Behaviors of the AI as infantry and in the different vehicles and sets a weight for each, which is used to determine the change that a bot will do a specific action in any situation. What we will show in this article is how the bot pathfinding is determined and that Roads are important to the pathfinding. AIbehaviors.AI file is in the mods\AI folder This file is also used to determine how the bots interact with the navmesh. In order to explain this we need to look at the AI.AI file in the AI folder of a map. This is a standard one from Dalian Plant: rem ************** LEVEL SPECIFIC AI SETTINGS *************************** rem aiSettings.setViewDistance 300 rem *** Init AI using current settings **** ai.init 2 aiPathfinding.setActiveMap Infantry aiPathfinding.map.maxSlope 37 aiPathfinding.map.addVehicleForClusterCost Infantery ''' aiPathfinding.setActiveMap '''Vehicle aiPathfinding.map.maxSlope 35 aiPathfinding.map.addVehicleForClusterCost Tank aiPathfinding.map.addVehicleForClusterCost ArmedCar aiPathfinding.map.addVehicleForClusterCost LandingCraft Notice the lines for AiPathfinding.map.addVehicleForClusterCost that are in Bold above. aiPathfinding.setActiveMap refers to the two different navmeshes in BF2/2142 for Infantry and Vehicles aiPathfinding.map.addVehicleForClusterCosts '''associates a pathfinding Cluster to a vehicle type. So Infantry will only associated with Infantery (DE is a Swedish company and likes to add an 'e' in infantry sometimes), while Tank, ArmedCar and LandingCraft are all associated with the Vehicle Navmesh. The Vehicle Cluster type is the Pathfinding cluster data used by the game to help navigate the bots around the map. There is no known way to show this info visually and we do not know the specific format of the pathfinding cluster data. '''NOTE: Not all maps tuse LandingCraft setting, which is used for all watercraft in BF2, while vehicles in BF2142 maps only uses the Tank setting. If vehicles that used ArmedCar or LandingCraft vehicle types or added to a map that was not navmeshed with these settings, the bots will go nowhere with them. They can not be added without re-navmeshing. Now going back to the mod AI\Aibehavior.AI file, close to start of the file, these lines can be found for BF2: aiSettings.setVehicleClusterMapping Tank Tank aiSettings.setVehicleClusterMapping Boat LandingCraft aiSettings.setVehicleClusterMapping Infantery Infantery aiSettings.setVehicleClusterMapping Car Tank aiSettings.setVehicleClusterMapping LandingCraft LandingCraft aiSettings.setVehicleClusterMapping ArmedCar ArmedCar aiSettings.setVehicleClusterMapping Amphibian ArmedCar aiSettings.setVehicleClusterMapping WaterCraft ArmedCar For BF2142 these lines will be found in the same file: aiSettings.setVehicleClusterMapping Tank Tank aiSettings.setVehicleClusterMapping Boat LandingCraft aiSettings.setVehicleClusterMapping Infantery Infantery aiSettings.setVehicleClusterMapping Car Tank aiSettings.setVehicleClusterMapping LandingCraft LandingCraft aiSettings.setVehicleClusterMapping ArmedCar ArmedCar Notice that BF2142 does not have an entry for Amphibian or WaterCraft, like in BF2. What these lines do is associate the vehicle type with the pathfinding cluster map. So, a vehicle using the car vehicle type will use the Tank pathfinding. Notice that even though BF2142 maps do not use LandingCraft for ArmedCar pathfinding, that the game is set up to support them. The only vehicle types that BF2142 is not currently set up to support is any that specifically use Amphibian or Watercraft. Now in the same file, each vehicle type will have Behavior setup info, with a lot of lines that are not important. The lines we are looking are the ones with aiSettings.setVehicleMaterialCost as shown below: rem *** Tank Behaviour setup *** aisettings.setVehicleMods Tank TankWeights aiSettings.setVehicleMaterialCost Tank Ground 1 aiSettings.setVehicleMaterialCost Tank Road 0.2 aiSettings.setVehicleMaterialCost Tank Shallows 1.5 aiSettings.setVehicleMaterialCost Tank DeepWater -1 aiSettings.setVehicleMaterialCost associates a vehicle type with a material type and gives each setting a weight. The different material settings are Ground, Road, Shallows or DeepWater. The closer to zero, the better chance the bots will use the vehicle on that surface type. Notice that Road is the ground (heightmap) distinction, not a navmesh material type. Where shallow and deepwater are distingushed on the navmesh, but not on the heightmap. Also, it appears that a weight of -1 means that area is off limits to the bots. In the example above for BF2 Tank, will avoid Deep water, prefers roads, but can go through shallow water. Infantry settings are : aiSettings.setVehicleMaterialCost Infantery Ground 1 aiSettings.setVehicleMaterialCost Infantery Road 0.6 aiSettings.setVehicleMaterialCost Infantery Shallows 1.5 aiSettings.setVehicleMaterialCost Infantery DeepWater 260 So, infantry bots will prefer to use Roads first, then Ground and Shallow Water, but they will get out of Deep Water as soon as possible (with a weight of 260!). Since most boats using the landincraft Pathfinding, lets look at the settings: aiSettings.setVehicleMaterialCost LandingCraft Ground 10 aiSettings.setVehicleMaterialCost LandingCraft Road 10 aiSettings.setVehicleMaterialCost LandingCraft Shallows 2 aiSettings.setVehicleMaterialCost LandingCraft DeepWater 1 Based on the weights, Boats prefer Deepwater, then shallows but shy away from ground and roads. Boats, on the other hand, can not use Ground or Roads and prefer Deep to shallow water: aiSettings.setVehicleMaterialCost Boat Ground -1 aiSettings.setVehicleMaterialCost Boat Road -1 aiSettings.setVehicleMaterialCost Boat Shallows 1 aiSettings.setVehicleMaterialCost Boat DeepWater 0.5 Watercraft vehicle type prefers deep water over shallow and will move away from the ground as soon as possible: aiSettings.setVehicleMaterialCost WaterCraft Ground 100 aiSettings.setVehicleMaterialCost WaterCraft Road 100 aiSettings.setVehicleMaterialCost WaterCraft Shallows 1 aiSettings.setVehicleMaterialCost WaterCraft DeepWater 0.5 An Armed Car can be used in Shallow and Deep Water and does not prefer roads over ground: aiSettings.setVehicleMaterialCost ArmedCar Ground 1 aiSettings.setVehicleMaterialCost ArmedCar Road 1 aiSettings.setVehicleMaterialCost ArmedCar Shallows 1 aiSettings.setVehicleMaterialCost ArmedCar DeepWater 2 An Amphibian vehicle prefers deep water over shallow and Roads over ground: aiSettings.setVehicleMaterialCost Amphibian Ground 1 aiSettings.setVehicleMaterialCost Amphibian Road 0.5 aiSettings.setVehicleMaterialCost Amphibian Shallows 1 aiSettings.setVehicleMaterialCost Amphibian DeepWater 0.5 The take away from all this is that when navmeshing, don't just copy over the Ai files from another map and start navmeshing without making sure that you are including the pathfinding files to support the vehicles on the map and any possible future use of the map. If the map has any water at all, it would not hurt to add the pathfinding for Landingcraft, and for BF2142 maps it would not hurt to add the pathfinding for ArmedCar. Now if your modding BF2142, you have be wondering what about Mechs? They use Tank pathfinding. There is no mech specific pathfinding. The only difference is that there were two lines added to the map's AI/AI file to support mechs for the vehicle navmesh setting: aiPathfinding.map.headClearance 7 This restricts navmeshing under bridges and other overhangs with a low clearance, below 7 meters in this case. and aiPathfinding.map.allowedThresholdHeight 0.1 '''This restricts pathfinding for entry ways that have a difference between the ground the entry of more than 0.1 meter in this case. If these lines are used for vehicle navmesh, Infantry are set as follows: '''aiPathfinding.map.headClearance 1.9 aiPathfinding.map.allowedThresholdHeight 1.0 These values are not required, so I am guessing that if not used, there are no head clearance and threshold restrictions for navmeshing.